#include <stdio.h>
#include <stdlib.h>

#include <utils/msp430lib.h>
#include <unistd.h>
#include <pthread.h>

#include "ui.h"
#include "kbd.h"
#include "rmt.h"

signed int main(signed int argc, unsigned char **argv) {
    if (msp430lib_init() == MSP430LIB_FAILURE) {
        fprintf(stderr, "Erro ao inicializar o controle remoto\n");
    }

    if (ui_init() == UI_FAILURE) {
        fprintf(stderr, "Erro ao criar a interface com o usuário\n");
        return EXIT_FAILURE;
    }

    printf("Interface inicializada com sucesso.\n");

    pthread_t kbd_thread;
    pthread_create(&kbd_thread, NULL, (void *) kbd_threadFunction, NULL);

    pthread_t rmt_thread;
    pthread_create(&rmt_thread, NULL, (void *) rmt_threadFunction, NULL);
    
    pthread_join(kbd_thread, NULL);
    fprintf(stderr, "Leitura do teclado desativada!\n");

    pthread_join(rmt_thread, NULL);
    fprintf(stderr, "Leitura do controle remoto desativada!\n");

    return EXIT_SUCCESS;
}
